from flask import Flask
import json
import pymysql

app = Flask(__name__)
db = pymysql.connect(host='localhost',user='root',password='123456',database='film')
cursor = db.cursor()

# with open('piaofang.json' , 'r',encoding='utf-8') as file:
#     data = json.load(file)
@app.route('/film/<film_name>')
def age(film_name):
    sql = "SELECT * FROM piaofang WHERE filmname = %s"
    cursor.execute(sql, (film_name,))
    result = cursor.fetchone()
    if result:
        return film_name+'的票房是'+result[1]+'，上映时间：'+result[2]
    else:
        for i in data['list']:
            if i['movieInfo']['movieName'] == film_name:
                return film_name+'票房为：'+i['sumBoxDesc']+'，上映时间：'+i['movieInfo']['releaseInfo']
        # return f'未找到电影"{film_name}"的票房数据'

if __name__=='__main__':
    app.run(debug=True,host='127.0.0.1' , port=1234)